﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using CMN.Models;
using CMN.Models.Interfaces;
using CMN.Entity;
using System.Web.Routing;
using CMN.Common;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using CMN.Controllers.Filters;
using CMN.Config;
namespace CMN.Controllers
{
    [ExceptionFilter]
    [LoggerFilter]
    [UserAuthorize]
    public class SiteInfoController : Controller
    {
        
        // 返回json字符串
        protected string returnJson = string.Empty;

        /// <summary>
        /// 转到View页面
        /// </summary>
        /// <returns></returns>
        public ViewResult Index()
        {
            return View("Index");//页面地址
        }

       

        /// <summary>
        /// 查看差评记录 
        /// </summary>
        /// <param name="id"></param>
        /// <returns>json</returns>
        public string Look(string actionId)
        {
            SiteConfigInfo site = SiteConfigs.GetSiteConfig();

            if (site != null)
                returnJson = string.Concat("{success:true,data:", JsonConvert.SerializeObject(site), "}");
            else
                returnJson = "{success:'false'}";
            return returnJson;
        }

        /// <summary>
        /// 更新差评记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns>json</returns>
        [ValidateInput(false)]
        public string Update()
        {
            
                SiteConfigInfo site = SiteConfigs.GetSiteConfig();
                site.Name = (String)Utils.GetQueryAndFormString("name", this, 120, 1, DataType.Str);
                site.Title = (String)Utils.GetQueryAndFormString("Title", this, 260, 1, DataType.Str);
                site.Url = (String)Utils.GetQueryAndFormString("Url", this, 150, 1, DataType.Str);
                site.Dir = (String)Utils.GetQueryAndFormString("Dir", this, 150, 0, DataType.Str);
                site.Keywords = (String)Utils.GetQueryAndFormString("Keywords", this, 250, 0, DataType.Str);
                site.Description = (String)Utils.GetQueryAndFormString("Description", this,250, 0, DataType.Str);
                site.IsHtml = (Int32)Utils.GetQueryAndFormString("IsHtml", this, 5, 1, DataType.Int);
                site.ChannelUrl = (String)Utils.GetQueryAndFormString("ChannelUrl", this, 40, 0, DataType.Str);
                site.ArticleUrl = (String)Utils.GetQueryAndFormString("ArticleUrl", this, 40, 0, DataType.Str);
                site.ICP = (String)Utils.GetQueryAndFormString("ICP", this, 40, 0, DataType.Str);
                site.CountJs = (String)Utils.GetQueryAndFormString("CountJs", this, 2000, 0, DataType.Str);
                site.CacheSecond = (Int32)Utils.GetQueryAndFormString("CacheSecond", this, 10, 1, DataType.Int);
                site.PagingNum = (Int32)Utils.GetQueryAndFormString("PagingNum", this, 10, 1, DataType.Int);
                site.MaxPageNum = (Int32)Utils.GetQueryAndFormString("MaxPageNum", this, 10, 1, DataType.Int);
                site.IsCacheTemplate = (bool)Utils.GetQueryAndFormString("IsCacheTemplate", this, 10, 1, DataType.Bool);
                site.IsZhanQun = (bool)Utils.GetQueryAndFormString("IsZhanQun", this, 10, 1, DataType.Bool);
                if ( SiteConfigs.SaveConfig(site))
                {
                    returnJson = "{success:'true'}";
                }
                else
                    returnJson = "{success:'false'}";
                SiteConfigs.ResetConfig();
           
           
            return returnJson;
        }

      

    }
}
